﻿using Application.UserApp.Dtos;
using AutoMapper;
using Domain.Entities;
using Domain.IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.UserApp
{
    /// <summary>
    /// 用户管理服务
    /// </summary>
    public class UserAppService : IUserAppService
    {
        //用户管理仓储接口
        private readonly IUserRepository _repository;

        /// <summary>
        /// 构造函数 实现依赖注入
        /// </summary>
        /// <param name="userRepository">仓储对象</param>
        public UserAppService(IUserRepository userRepository)
        {
            _repository = userRepository;
        }

        public User CheckUser(string userName, string password)
        {
            return _repository.CheckUser(userName, password);
        }


        public List<User> GetAll(string key)
        {
            return _repository.GetAll(key).ToList();
        }
        public List<User> GetAll(int roleid)
        {
            return _repository.GetAll(roleid).ToList();
        }
        public List<User> GetPageList(string SearchKeyWords, int PageSize, int PageCurrent, string OrderField, bool OrderDirection = true)
        {
            return _repository.GetPageList(SearchKeyWords, PageSize, PageCurrent, OrderField, OrderDirection).ToList();
        }

        public User GetById(int id) {
            return _repository.GetById(id);
        }

        public User GetByLoginname(string loginname)
        {
            return _repository.GetByLoginname(loginname);
        }


        public bool AddOrUpdate(User model)
        {
            return _repository.AddOrUpdate(model);
        }

        public bool DeleteById(int id)
        {
            return _repository.DeleteById(id);
        }
    }
}
